import sympy as sp
x, y = sp.symbols('x y')

psi00 = (1-x) * (1-y)
psi10 = x * (1-y)
psi11 = x * y
psi01 = (1-x) * y

dpsi00x = y-1
dpsi10x = 1-y
dpsi11x = y
dpsi01x = -y
dpsi00y = x-1
dpsi10y = -x
dpsi11y = x
dpsi01y = 1-x

# ij, ij
print(sp.integrate(psi00 ** 2 + psi10 ** 2 + psi11 ** 2 + psi01 ** 2, (x, 0, 1), (y, 0, 1)))

# ij, (i+1)j
print(sp.integrate(psi00 * psi10 + psi01 * psi11, (x, 0, 1), (y, 0, 1)))

# ij, (i-1)j
print(sp.integrate(psi10 * psi00 + psi11 * psi01, (x, 0, 1), (y, 0, 1)))

# ij, i(j+1)
print(sp.integrate(psi00 * psi01 + psi10 * psi11, (x, 0, 1), (y, 0, 1)))

# ij, i(j-1)
print(sp.integrate(psi11 * psi10 + psi01 * psi00, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j-1)
print(sp.integrate(psi11 * psi00, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j-1)
print(sp.integrate(psi01 * psi10, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j+1)
print(sp.integrate(psi00 * psi11, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j+1)
print(sp.integrate(psi10 * psi01, (x, 0, 1), (y, 0, 1)))

print("\n")

# Laplace项

# ij, ij
print(sp.integrate(dpsi00x ** 2 + dpsi10x ** 2 + dpsi11x ** 2 + dpsi01x ** 2, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi00y ** 2 + dpsi10y ** 2 + dpsi11y ** 2 + dpsi01y ** 2, (x, 0, 1), (y, 0, 1)))

# ij, (i+1)j
print(sp.integrate(dpsi00x * dpsi10x + dpsi01x * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi00y * dpsi10y + dpsi01y * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij, (i-1)j
print(sp.integrate(dpsi10x * dpsi00x + dpsi11x * dpsi01x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi10y * dpsi00y + dpsi11y * dpsi01y, (x, 0, 1), (y, 0, 1)))

# ij, i(j+1)
print(sp.integrate(dpsi00x * dpsi01x + dpsi10x * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi00y * dpsi01y + dpsi10y * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij, i(j-1)
print(sp.integrate(dpsi11x * dpsi10x + dpsi01x * dpsi00x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi11y * dpsi10y + dpsi01y * dpsi00y, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j-1)
print(sp.integrate(dpsi11x * dpsi00x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi11y * dpsi00y, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j-1)
print(sp.integrate(dpsi01x * dpsi10x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi01y * dpsi10y, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j+1)
print(sp.integrate(dpsi00x * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi00y * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j+1)
print(sp.integrate(dpsi10x * dpsi01x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi10y * dpsi01y, (x, 0, 1), (y, 0, 1)))

print("\n")

# 线性项

# ij, ij
print(sp.integrate(dpsi00x * psi00 + dpsi10x * psi10 + dpsi11x * psi11 + dpsi01x * psi01, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(dpsi00y * psi00 + dpsi10y * psi10 + dpsi11y * psi11 + dpsi01y * psi01, (x, 0, 1), (y, 0, 1)))

# ij, (i+1)j
print(sp.integrate(psi00 * dpsi10x + psi01 * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi00 * dpsi10y + psi01 * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij, (i-1)j
print(sp.integrate(psi10 * dpsi00x + psi11 * dpsi01x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi10 * dpsi00y + psi11 * dpsi01y, (x, 0, 1), (y, 0, 1)))

# ij, i(j+1)
print(sp.integrate(psi00 * dpsi01x + psi10 * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi00 * dpsi01y + psi10 * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij, i(j-1)
print(sp.integrate(psi11 * dpsi10x + psi01 * dpsi00x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi11 * dpsi10y + psi01 * dpsi00y, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j-1)
print(sp.integrate(psi11 * dpsi00x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi11 * dpsi00y, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j-1)
print(sp.integrate(psi01 * dpsi10x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi01 * dpsi10y, (x, 0, 1), (y, 0, 1)))

# ij,(i+1)(j+1)
print(sp.integrate(psi00 * dpsi11x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi00 * dpsi11y, (x, 0, 1), (y, 0, 1)))

# ij,(i-1)(j+1)
print(sp.integrate(psi10 * dpsi01x, (x, 0, 1), (y, 0, 1)))
print(sp.integrate(psi10 * dpsi01y, (x, 0, 1), (y, 0, 1)))